package com.example.androiddemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.wifi.hotspot2.pps.HomeSp;
import android.os.AsyncTask;
import android.os.Bundle;

import com.example.androiddemo.contentproviderdemo.ContentProviderMainActivity;
import com.example.androiddemo.day713.BroadcastActivity;
import com.example.androiddemo.day714.MusicService;
import com.example.androiddemo.day714.ServiceActivity;
import com.example.androiddemo.day715.MediaPlayerActivity;
import com.example.androiddemo.day719.SharedPreferenceActivity;

import javax.net.ssl.HostnameVerifier;

public class MainActivity extends AppCompatActivity {
    private Intent startMusicIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        startMusicIntent = new Intent(this, MusicService.class);
        startMusicIntent.putExtra("cmd", 0);
        startService(startMusicIntent);//应用启动是开启音乐播放服务，并打开通知栏

        Intent intent = new Intent(this, MediaPlayerActivity.class);
        startActivity(intent);
    }

    // activity被销毁后销毁服务。
    @Override
    protected void onDestroy() {
        super.onDestroy();
        stopService(startMusicIntent);
    }


    // 按下返回键是回到桌面，但是不会执行finish销毁activity.
    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        Intent intent=new Intent(Intent.ACTION_MAIN); //设置该intent的action为action main。相当于调用了setAction
        intent.addCategory(Intent.CATEGORY_HOME); //添加category
        startActivity(intent);
    }
}